<?php
    // Sept 28, 2010 - immanuel192 - create this module

    class imageslidermodule {
        function name() { return "Imageslider"; }
        function description() { return "Show an image slider. All images you can add from imagegallery module"; }
        function author() { return "immanuel192 - ABSoft.vn"; }

        function hasSources() { return true; }
        function hasContent() { return true; }
        function hasViews() { return true; }

        function supportsWorkflow() { return false; }

        function permissions($internal = "") {
            /* Sept 28, 2010: immanuel192  - permission details - begin
            - Configure: Add & Edit
            - Administrate: Configure & Delete
            Sept 28, 2010: immanuel192  - permission details - end */
            return array(
            'administrate'=>'Administrate',
            'configure'=>'Configure'
            );
        }

        function show($view,$loc = null, $title = "") {
            global $db;

            $config = $db->selectObject('imageslidermodule_config',"location_data='".serialize($loc)."'");
            if ($config == null) {
                $config->orderby = 0;
                $config->image_col=0;
            }
            
            // sort build sql
            $sSQLSort="";
            if ($config->orderby == 1)
            {
                $sSQLSort=" ORDER BY name ASC";
            }
            else
            if ($config->orderby == 2)
            {
                $sSQLSort=" ORDER BY name DESC";
            }
            else
            if ($config->orderby == 3)
            {
                $sSQLSort=" ORDER BY rand()";
            }
            else
            {
                $sSQLSort=" ORDER BY rank";
            }
            // end  sort
            $links = $db->selectObjects('imageslider_image',"location_data='".serialize($loc)."' {$sSQLSort}");
            foreach ($links as $key=>$value){
                // check file id
                if ($value->file_id == 0) {
                    $value->picpath = '';
                } else {
                    $file = $db->selectObject('file', 'id='.$value->file_id);
                    // 10/01/2010 - immanuel192 - fix bug FILE RELATIVE not work with SEO - begin
                    $value->picpath = BASE_URL . "/".$file->directory.'/'.$file->filename;
                    // 10/01/2010 - immanuel192 - fix bug FILE RELATIVE not work with SEO - end 
                    $links[$key]=$value;
                }
            }
            $template = new template('imageslidermodule',$view,$loc);
            // 09/29/2010 - immanuel192 - UI LEVEL Check - begin
            $level = 99;
            if (exponent_sessions_isset('uilevel')) {
                $level = exponent_sessions_get('uilevel');
            }
            $template->assign('editMode',exponent_sessions_loggedIn() && $level != UILEVEL_PREVIEW);
            // 09/29/2010 - immanuel192 - UI LEVEL Check - end
            $template->assign('links',$links);
            $template->assign('link_count',count($links));
            $template->assign('moduletitle',$title);
            $template->register_permissions(array('administrate','configure'),$loc);
            $template->output();
        }

        function deleteIn($loc) {
            global $db;
            $db->delete('imageslider_image',"location_data='".serialize($loc)."'");
        }

        function copyContent($oloc,$nloc) {
            foreach ($db->selectObjects('imageslider_image',"location_data='".serialize($oloc)."'") as $l) {
                $l->location_data = serialize($nloc);
                $db->insertObject($l,'imageslider_image');
            }
        }

        /* Sept 28, 2010 - immanuel192 - remove search feature - begin
        function searchName() {
        return exponent_lang_loadKey('modules/imageslidermodule/class.php','search_name');
        }


        function spiderContent($item = null) {
        global $db;

        if (!defined('SYS_SEARCH')) require_once(BASE.'subsystems/search.php');

        $search = null;
        $search->category = 'Links';
        $search->ref_module = 'linklistmodule';
        $search->ref_type = 'linklist_link';
        $search->view_link = '';

        if ($item) {
        $db->delete('search',"ref_module='linklistmodule' AND ref_type='linklist_link' AND original_id=" . $item->id);
        $search->original_id = $item->id;
        $search->title = ' ' . $item->name . ' ';
        $search->body = ' ' . exponent_search_removeHTML($item->description) . ' ';
        $search->location_data = $item->location_data;
        $db->insertObject($search,'search');
        } else {
        $db->delete('search',"ref_module='linklistmodule' AND ref_type='linklist_link'");
        foreach ($db->selectObjects('linklist_link') as $item) {
        $search->original_id = $item->id;
        $search->title = ' ' . $item->name . ' ';
        $search->body = ' ' . exponent_search_removeHTML($item->description) . ' ';
        $search->location_data = $item->location_data;
        $db->insertObject($search,'search');
        }
        }

        return true;
        }
        */
    }

?>
